<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            客户抱怨分配
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

        <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">客户</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入客户" id="client" value="" onclick="getIdSelector();" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">产品名称</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入产品名称" id="mrlName" value="" onclick="getIdSelector();" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">产品图号</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入产品图号" id="mrlTuhao" value=""
                                onclick="getIdSelector();" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width:150px">发生时间</div>
                        <div class="aui-list-item-input" onclick="timePicker();">
                            <input type="text" placeholder="选择日期" class="aui-input" id="informationTime">
                        </div>
                    </div>
                </li>
            </ul>
        </div>

        <div class="aui-btn aui-btn-info" style="width:40%;margin-left:6%;" onclick="doSearch()">查询</div>
        <!-- <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="submit()">提报</div> -->
        <div class="aui-btn aui-btn-info" style="width:40%;margin-left:6%;" onclick="swipeCard()">分配</div>
        <div
            style="background-color:white; width: 100%;margin-top:2%;overflow-x: auto;-webkit-overflow-scrolling:touch;">
            <table class="table" style='width:4400px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style='width: 40px;'></td>
                        <td algin='center' style='width:200px;'>状态</td>
                        <td algin='center' style='width:200px;'>发生时间</td>
                        <td algin='center' style='width:200px;'>客户</td>
                        <td algin='center' style='width:200px;'>问题发生环节</td>
                        <td algin='center' style='width:200px;'>生产单位</td>
                        <td algin='center' style='width:200px;'>产品名称</td>
                        <td algin='center' style='width:200px;'>产品图号</td>
                        <td algin='center' style='width:200px;'>产品状态</td>
                        <td algin='center' style='width:200px;'>生产批次</td>
                        <td algin='center' style='width:200px;'>问题描述</td>
                        <td algin='center' style='width:200px;'>问题数量</td>
                        <td algin='center' style='width:200px;'>问题原因类型</td>
                        <td algin='center' style='width:200px;'>结果或严重性描述</td>
                        <td algin='center' style='width:200px;'>问题判定</td>
                        <td algin='center' style='width:200px;'>责任单位</td>
                        <td algin='center' style='width:200px;'>原因分析</td>
                        <td algin='center' style='width:200px;'>改进措施</td>
                        <td algin='center' style='width:200px;'>措施文件化</td>
                        <td algin='center' style='width:200px;'>负责单位</td>
                        <td algin='center' style='width:200px;'>完成时间</td>
                        <td algin='center' style='width:200px;'>问题处理结果及跟踪验证</td>
                        <td algin='center' style='width:200px;'>质量工程师</td>
                        <td algin='center' style='width:200px;display:none;'>sysid</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:4400px;' id="table">
                <tbody id="tbodyHtml" style="display: block;height: 500px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>

        <!--弹出备注 -->
        <div id="shade" class="c1 hide"></div>
        <div id="modal" class="c2 hide">
            <p style="margin-left: 10px;font-size: 1rem;font-weight: 500;color: #212121;text-align: center;"></p>
            <ul class="aui-list aui-form-list" style="margin-top: 1%;overflow-y: auto; ">
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">结果或严重性描述</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="结果或严重性描述" id="problemResult" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">问题判定</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="问题判定" id="problemDecide" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">责任单位</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="责任单位" id="responsibilityUnit" />
                        </div>
                    </div>
                </li>

                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">原因分析</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="原因分析" id="causeAnalysis" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">改进措施</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="改进措施" id="improvementMeasures" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">措施文件化</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="措施文件化" id="measuresDocumented" />
                        </div>
                    </div>
                </li>

                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">完成时间</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="完成时间" id="completeDate" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 250px">质量工程师</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="质量工程师" id="qualityEngineer" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 300px">问题处理结果及跟踪验证</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="问题处理结果及跟踪验证" id="problemHandling" />
                        </div>
                    </div>
                </li>

            </ul>
            <div style="display: flex;
                         justify-content: space-around;
                         padding-top: 10px;
                         padding-bottom: 10px;">
                <div class="aui-btn aui-btn-info" style="width:30%;margin-top:2%;" onclick="Hide()">取消
                </div>
                <div class="aui-btn aui-btn-info" style="width:30%;margin-top:2%;" onclick="changeState()">确定
                </div>
            </div>
        </div>
    </div>

    <!-- <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer> -->
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var workCenterGid = ""; //仓库GID
    var workCenterCode = ""; //仓库编码
    var workCenterName = ""; //仓库名称
    var workCellGid = ""; //库位GID
    var workCellCode = ""; //库位编码
    var workCellName = ""; //库位名称

    //初始化
    apiready = function () {
        $("#client").focus();
        idSelector = "clent";
        doSearch();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间选择器
    function timePicker() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#informationTime").val(date);
            }
        });
    }

    //查询
    function doSearch() {
        var informationTime = $("#informationTime").val();//发生时间
        var mrlName = $("#mrlName").val();//产品名称
        var mrlTuhao = $("#mrlTuhao").val();//产品图号

        var client = $("#client").val();//客户

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getKmManngerSubmit";
        var data = {
            values: {
                // ext06: '1,5',
                username: un,
                informationTime: informationTime,
                mrlName: mrlName,
                mrlTuhao: mrlTuhao,
                client: client,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td style='width:40px;'><input name='sub' type='checkbox' /></td>";
                        html += "<td name='ext05' style='width:200px;'>" + InitStatus(list[i].ext05) + "</td>";
                        html += "<td name='informationTime' style='width:200px;'>" + list[i].informationTime + "</td>";
                        html += "<td name='client' style='width:200px;'>" + list[i].client + "</td>";
                        html += "<td name='problemOccurs' style='width:200px;'>" + list[i].problemOccurs + "</td>";
                        html += "<td name='productionUnits' style='width:200px;'>" + list[i].productionUnits + "</td>";
                        html += "<td name='mrlName' style='width:200px;'>" + list[i].mrlName + "</td>";
                        html += "<td name='mrlTuhao' style='width:200px;'>" + list[i].mrlTuhao + "</td>";
                        html += "<td name='mrlStatus' style='width:200px;'>" + list[i].mrlStatus + "</td>";
                        html += "<td name='lotCode' style='width:200px;'>" + list[i].lotCode + "</td>";
                        html += "<td name='problemDescription' style='width:200px;'>" + list[i].problemDescription + "</td>";
                        html += "<td name='problemNum' style='width:200px;'>" + list[i].problemNum + "</td>";
                        html += "<td name='problemCause' style='width:200px;'>" + list[i].problemCause + "</td>";
                        html += "<td name='problemResult' style='width:200px;'>" + list[i].problemResult + "</td>";
                        html += "<td name='problemDecide' style='width:200px;'>" + list[i].problemDecide + "</td>";
                        html += "<td name='responsibilityUnit' style='width:200px;'>" + list[i].responsibilityUnit + "</td>";
                        html += "<td name='causeAnalysis'style='width:200px;' >" + list[i].causeAnalysis + "</td>";
                        html += "<td name='improvementMeasures' style='width:200px;'>" + list[i].improvementMeasures + "</td>";
                        html += "<td name='measuresDocumented' style='width:200px;'>" + list[i].measuresDocumented + "</td>";
                        html += "<td name='responsibilityPerson' style='width:200px;'>" + list[i].responsibilityPerson + "</td>";
                        html += "<td name='completeDate' style='width:200px;'>" + list[i].completeDate + "</td>";
                        html += "<td name='problemHandling' style='width:200px;'>" + list[i].problemHandling + "</td>";
                        html += "<td name='qualityEngineer'style='width:200px;' >" + list[i].qualityEngineer + "</td>";
                        html += "<td name='sysid'style='width:200px;display:none' >" + list[i].sysid + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    // 1待处理
    // 2待审核
    // 3审核不通过
    // 4待复审
    // 5复审不通过
    // 6待关闭
    // 7客户审核不通过
    // 8已关闭
    // 9待分配
    function InitStatus(status) {
        console.log(status)
        if (status == '1') {
            return '待处理'
        } else if (status == '2') {
            return '待审核'
        }
        else if (status == '3') {
            return '审核不通过'
        }
        else if (status == '4') {
            return '待复审'
        }
        else if (status == '5') {
            return '复审不通过'
        }
        else if (status == '6') {
            return '待关闭'
        }
        else if (status == '7') {
            return '客户审核不通过'
        }
        else if (status == '8') {
            return '已关闭'
        }
        else if (status == '9') {
            return '待分配'
        }
    }

    function submit() {
        api.openWin({
            name: 'qckmmanagesubmitdetail',
            url: 'qckmmanagesubmitdetail.html',
            pageParam: {
                name: "qckmmanagesubmit",
            }
        });
    }
    function swipeCard() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function () {
            count++;
        });

        //选中行不为1
        if (count != 1) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        var ids = "";
        var status = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            var sysid = row.find("[name='sysid']").html();
            status = row.find("[name='ext05']").html();
            ids += "" + sysid + ","
        });

        if (ids) {
            ids = ids.substring(0, ids.length - 1);
        }
        if (status != '待分配') {
            api.toast({
                msg: '只有状态为待分配才可分配！',
                duration: 3000
            });
            return;
        }
        console.log(ids)

        api.openWin({
            name: 'qckmmanage-assign-detail',
            url: 'qckmmanage-assign-detail.html',
            pageParam: {
                name: "qckmmanage-assign",
                ids: ids,
            }
        });
    }
    function Hide() {
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
    }
    function dealSuccess() {
        doSearch();
    }
    function changeState(type) {

        var problemResult = $("#problemResult").val();
        var problemDecide = $("#problemDecide").val();
        var responsibilityUnit = $("#responsibilityUnit").val();
        var causeAnalysis = $("#causeAnalysis").val();
        var improvementMeasures = $("#improvementMeasures").val();
        var measuresDocumented = $("#measuresDocumented").val();
        var completeDate = $("#completeDate").val();
        var qualityEngineer = $("#qualityEngineer").val();
        var problemHandling = $("#problemHandling").val();

        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function () {
            count++;
        });

        //选中行不为1
        if (count != 1) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        var ids = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            var sysid = row.find("[name='sysid']").html();

            ids += "" + sysid + ","
        });

        if (ids) {
            ids = ids.substring(0, ids.length - 1);
        }
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getKmManngerChangeState";

        api.showProgress({
            title: '保存中...',
        });

        var data = {
            values: {
                type: 'cl',
                ids: ids,
                problemResult: problemResult,
                problemDecide: problemDecide,
                responsibilityUnit: responsibilityUnit,
                causeAnalysis: causeAnalysis,
                improvementMeasures: improvementMeasures,
                measuresDocumented: measuresDocumented,
                completeDate: completeDate,
                qualityEngineer: qualityEngineer,
                problemHandling: problemHandling,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    Hide();
                    doSearch();
                    $("#problemResult").val("");
                    $("#problemDecide").val("");
                    $("#responsibilityUnit").val("");
                    $("#causeAnalysis").val("");
                    $("#improvementMeasures").val("");
                    $("#measuresDocumented").val("");
                    $("#completeDate").val("");
                    $("#qualityEngineer").val("");
                    $("#problemHandling").val("");
                } else if (myobj.code == "1") {

                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    function closeDialog() {
        var dialogBox = api.require('dialogBox');
        dialogBox.close({
            dialogName: 'input'
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

<style>
    .c1 {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .5);
        z-index: 99;
        margin-top: 0%;
    }

    .c2 {
        background-color: white;
        position: fixed;
        width: 400px;
        height: 300px;
        top: 50%;
        left: 50%;
        z-index: 100;
        margin-top: -125px;
        margin-left: -200px;
        padding-top: 2%;
        padding-left: 2%;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .hide {
        display: none;
    }
</style>

</html>